package converter.core.db;

import converter.core.db.entity.SysUsers;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

/**
 * Created with IntelliJ IDEA.
 * User: Snark
 * Date: 28.03.13
 * Time: 23:06
 * To change this template use File | Settings | File Templates.
 */
public class DataManager {

    private static DataManager instance;

    public final EntityManager em;

    private DataManager() {
        em = Persistence.createEntityManagerFactory("xconverter-ws-persistance-unit").createEntityManager();
    }

    public static DataManager get() {
        if (instance == null) {
            instance = new DataManager();
        }
        return instance;
    }

    public void persist(Object object) {
        em.clear();
        em.getTransaction().begin();
        em.persist(object);
        em.getTransaction().commit();
    }
}
